﻿using CommunityToolkit.Mvvm.Input;
using HslCommunication.Profinet.Siemens;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Animation;
using ZoneLineNew.Common;
using ZoneLineNew.Core;
using ZoneLineNew.Core.Extensions;
using ZoneLineNew.Enums;
using ZoneLineNew.Models;
using ZoneLineNew.Models.Dto;
using ZoneLineNew.Models.Entity;
using ZoneLineNew.Models.Entity.BaseInfo;
using ZoneLineNew.Models.StationConfig;
using ZoneLineNew.Models.StationResult.HOPStation;
using ZoneLineNew.Models.StationResult.QOPStation;
using ZoneLineNew.Services.DB;
using ZoneLineNew.Services.Message;
using ZoneLineNew.Services.Station;
using ZoneLineNew.ViewModelBase;
using ZoneLineNew.Views.Dialogs;

namespace ZoneLineNew.ViewModels {

    public class MainTwoViewModel : NavigationViewModel {

        private readonly IDbOperate<IFreeSqlMainContext> _mainDbOperate = null;

        public MainTwoViewModel(
            IRegionManager regionManager,
            IDialogService dialog,
            IMessageService messageBox,
            IEventAggregator eventAggregator,
            IDbOperate<IFreeSqlMainContext> mainDbOperate,
            IWorkStationService<HOP010StationResult, HOP010StationConfig> workStationHOP010Service,
            IWorkStationService<HOP040StationResult, HOP040StationConfig> workStationHOP040Service
            ) : base(regionManager, dialog, messageBox, eventAggregator, mainDbOperate) {

            this._mainDbOperate = mainDbOperate;

            if (Cache.IsHopStaion) {
                WorkStationHOP010Service = workStationHOP010Service;
                WorkStationHOP040Service = workStationHOP040Service;
                WorkStationHOP010Service.Connect();
                WorkStationHOP040Service.Connect();
            }
        }


        #region Props
        private bool _isCheckOK = false;

        public bool IsCheckOK {
            get { return _isCheckOK; }
            set { _isCheckOK = value; RaisePropertyChanged(); }
        }


        #region 后减
        private IWorkStationService<HOP010StationResult, HOP010StationConfig> _workStationHOP010Service;

        public IWorkStationService<HOP010StationResult, HOP010StationConfig> WorkStationHOP010Service {
            get { return _workStationHOP010Service; }
            set { _workStationHOP010Service = value; base.RaisePropertyChanged(); }
        }


        private IWorkStationService<HOP040StationResult, HOP040StationConfig> _workStationHOP040Service;

        public IWorkStationService<HOP040StationResult, HOP040StationConfig> WorkStationHOP040Service {
            get { return _workStationHOP040Service; }
            set { _workStationHOP040Service = value; base.RaisePropertyChanged(); }
        }
        #endregion


        private string _customer = "产品未选择";

        public string Customer {
            get { return _customer; }
            set { _customer = value; base.RaisePropertyChanged(); }
        }

        private string _model = "型号未选择";

        public string Model {
            get { return _model; }
            set { _model = value; base.RaisePropertyChanged(); }
        }

        private string _workDirection = "方向未选择";

        public string WorkDirection {
            get { return _workDirection; }
            set { _workDirection = value; base.RaisePropertyChanged(); }
        }
        #endregion

        #region Commands

        public DelegateCommand SelectProductCommand => new DelegateCommand(() => {
            DialogParameters dialogParameters = new DialogParameters();
            dialogParameters.Add("Title", "产品选择");
            _dialog.ShowDialog(nameof(SelectProductDialogView), dialogParameters, (rhs) => {
                IsCheckOK = rhs.Result == ButtonResult.OK;
                if (IsCheckOK) {
                    Customer = Cache.CurWorkProduct.CustomerName;
                    Model = Cache.CurWorkProduct.Model;
                    WorkDirection = Cache.CurWorkProduct.WorkDirection.GetDescription();
                    WorkStationHOP040Service.GetCurrentLableIndex(ePrintStartionCode.H_OP640);
                }
            });
        });

        #endregion




        protected override void OnViewLoaded() {
          

            //base.OnViewLoaded();
        }




       

    }
}
